<%@page import="java.rmi.Remote"%>
<%@ page language="java" import="java.util.*,mySql.*" pageEncoding="utf-8"%>
<%@ page import="show_shop.*" %>
<%@ page import="java.sql.PreparedStatement"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="java.sql.Connection"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'inser_goods_my_sql.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
   
   
   <%   
   			String login_name="root";
			String login_password="2014121167";
			String driverClass="com.mysql.jdbc.Driver";
			String url="jdbc:mysql://localhost:3306/test";
			Connection con=null;
			PreparedStatement pst=null;
			int rs;
			
			
			user_bean user=new user_bean();
   			ArrayList<goods_bean>  shop_car=new ArrayList<goods_bean>();
  		 	shop_car=(ArrayList<goods_bean>)session.getAttribute("car_session");
			user=(user_bean)session.getAttribute("feng");
			
			
			DBConnection dbcon=new DBConnection(driverClass,url,login_password,login_name);
			try
			{
					con=dbcon.getConnection();
					//System.out.println("mysql_insert_goodsmessage link ok!");

					for(int k=0;k<shop_car.size();k++)
					{
					pst=con.prepareStatement("insert into all_user_buy values(?,?,?,?,?)");
					pst.setString(1,user.getUsername());
					pst.setString(2,user.getPassword() );
					pst.setString(3,shop_car.get(k).getName());
					pst.setString(4,"1");
					pst.setString(5,shop_car.get(k).getPrice());
					
					//System.out.println(user.getUsername());
					//System.out.println(user.getPassword() );
					//System.out.println(shop_car.get(k).getName());
					//System.out.println(shop_car.get(k).getPrice());
	
					rs=pst.executeUpdate();
					
					response.setHeader("refresh", "1;URL="+"http://localhost:8080/practise/index.jsp");
					out.print("下单成功!");
					}
					
				session.removeAttribute("car_session");
		
			}
   			catch (Exception e) {
				e.getStackTrace();
				e.printStackTrace();
			}
   
   %>
 
   
   
   
   
   
   
   
   
   
   
   
   
  </body>
</html>
